import { Component ,OnInit} from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-page-category',
  templateUrl: './page-category.component.html',
  styleUrls: ['./page-category.component.scss']
})
export class PageCategoryComponent implements OnInit{
  tagList = ["推荐",  "手机",  "平板",  "电脑",  
  "智能穿戴",   "智能家居",  
     "有品精选"]


   goodsList:any=[
   
   ]

   async loadListByCateId(cateId:string|number){
     //获取商品信息
     let list = await this.getGoods(cateId)
     this.goodsList = list
   }
   async ngOnInit(): Promise<void> {
    this.loadListByCateId("0")
 
 //创建操作
 // let Goods = Parse.Object.extend("goods");
 // let xiaoming = new Goods;
 // let goodsJson = {goodsID:"006",goodsName:"苹果Apple iPhone 19",goodsPrice:"5399",
 // goodsDetail:"支持移动联通电信5G 双卡双待手机",goodsImg:"../../assets/images/6/poster.jpg",
 // goodsNumber:0,goodsCategory:"1",goodsComment:"98",detailImgPath:[
 //   "../../assets/images/6/detail_1.jpg",
 //   "../../assets/images/6/detail_2.jpg",
 //   "../../assets/images/6/detail_3.jpg",
 // ]}
 // xiaoming.set(goodsJson)
 // xiaoming.save();
 
 
 
 // 查询Student
 //     let query = new Parse.Query("goods")
 //     query.equalTo("goodsID","006")
 //     query.limit(1)
 //     let slist = await query.find()
 //     console.log(slist)
 
 // 修改Student
 //     let query2 = new Parse.Query("goods")
 //     let stu1 = await query2.get("GvzX0WaRuR");
 //     stu1.set("goodsID","19")
 //     stu1.save()
 
   // 删除Student
 //     let query3 = new Parse.Query("goods")
 //     let stu2 = await query3.get("SSod4F3BSl");
 //     stu2.destroy()
 //  {
 
 // }
   }
 
 
 
     async getGoods(cateId:string|number){
     let result = await fetch(`http://metapunk.cn:9999/parse/classes/goods?where={"goodsCategory":"${cateId}"}`, {
       "headers": {
         "accept": "*/*",
         "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
         "if-none-match": "W/\"2b1-MU/Itc7uoKG+Snjx4wd2HA45/FA\"",
         "x-parse-application-id": "dev"
       },
       "referrer": "http://localhost:4040/",
       "referrerPolicy": "strict-origin-when-cross-origin",
       "body": null,
       "method": "GET",
       "mode": "cors",
       "credentials": "omit"
     });
     let data = await result.json();
     console.log(data)
     let list = data?.results
     return list
   }

  currentTag=0
   clickIn(tag:any){
    this.currentTag=tag
    console.log(tag)
    this.loadListByCateId(tag)
   }
   clickDetail(item:any) {
    console.log(item+"category");
     this.router.navigate(["./intelligent-shopping/detail"],{
        queryParams:{
            id:item.objectId
  }
     })
  }
  constructor(private router:Router){
  
  }
  //搜索
  clickInput(){
    this.router.navigate(["./intelligent-shopping/search"],{
         })
  }
}

